package cn.edu.baiyunu.myapplication.data.repository

import cn.edu.baiyunu.myapplication.data.dao.SavingsGoalDao
import cn.edu.baiyunu.myapplication.data.model.SavingsGoal
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import javax.inject.Singleton

/**
 * SavingsGoalRepository接口的实现类
 */
@Singleton
class SavingsGoalRepositoryImpl @Inject constructor(
    private val savingsGoalDao: SavingsGoalDao
) : SavingsGoalRepository {
    
    override fun getAllSavingsGoals(): Flow<List<SavingsGoal>> {
        return savingsGoalDao.getAllSavingsGoals()
    }
    
    override fun getSavingsGoalById(id: String): Flow<SavingsGoal?> {
        return savingsGoalDao.getSavingsGoalById(id)
    }
    
    override suspend fun addSavingsGoal(savingsGoal: SavingsGoal) {
        savingsGoalDao.insertSavingsGoal(savingsGoal)
    }
    
    override suspend fun updateSavingsGoal(savingsGoal: SavingsGoal) {
        savingsGoalDao.updateSavingsGoal(savingsGoal)
    }
    
    override suspend fun deleteSavingsGoal(id: String) {
        savingsGoalDao.deleteSavingsGoalById(id)
    }
    
    override fun getSavingsProgress(): Flow<Map<String, Double>> {
        // 这里应该实现获取储蓄进度的逻辑
        // 暂时简单返回一个空的Map
        return getAllSavingsGoals().map { goals ->
            goals.associate { it.id to 0.0 }
        }
    }
} 